package edu.tjut.tjutcommunity.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class NoticeMessage implements Serializable {

    //消息发起时间
//    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
//    @JSONField(format="yyyy-MM-dd HH:mm:ss")
    String createTime = String.valueOf(new Date().getTime());
    //消息类型 0 回复， 1点赞
    Integer type;
    //发起用户id
    Integer uid;
    //发起用户用户名
    String username;
    //帖子id
    Integer pid;
    //楼层id
    Integer fid;
    //消息id
    String messageId;
    //消息内容
    String content;

    /**
     * 帖子被点赞 type=1
     * @param from
     * @param id
     * @return
     */
    public static NoticeMessage getLikeMessage(User from,Integer pid){
        NoticeMessage noticeMessage = new NoticeMessage();
        noticeMessage.setContent(from.getUsername()+"给你点赞了");
        noticeMessage.setUid(from.getUid());
        noticeMessage.setPid(pid);
        noticeMessage.setType(1);
        noticeMessage.setUsername(from.getUsername());
        return noticeMessage;
    }

    /**
     * 帖子被回复，type=2
     * @param from
     * @param id
     * @param content
     * @return
     */
    public static NoticeMessage getReplyPostMessage(User from,Integer id,String content){
        NoticeMessage noticeMessage = new NoticeMessage();
        noticeMessage.setContent(content);
        noticeMessage.setUid(from.getUid());
        noticeMessage.setPid(id);
        noticeMessage.setType(2);
        noticeMessage.setUsername(from.getUsername());
        return noticeMessage;
    }

    /**
     * 楼层被回复，type=3
     * @param from
     * @param id
     * @param content
     * @return
     */
    public static NoticeMessage getReplyFloorMessage(User from,Integer fid,Integer pid,String content){
        NoticeMessage noticeMessage = new NoticeMessage();
        noticeMessage.setContent(content);
        noticeMessage.setUid(from.getUid());
        noticeMessage.setFid(fid);
        noticeMessage.setPid(pid);
        noticeMessage.setType(3);
        noticeMessage.setUsername(from.getUsername());
        return noticeMessage;
    }

}
